//
//  Course.m
//  RepasoApp
//
//  Created by Vicente Vicens Camarena on 02/10/11.
//  Copyright 2011 Imathink World, S.L.N.E. All rights reserved.
//

#import "Course.h"
#import "Resource.h"
#import "Event.h"

@implementation Course

@synthesize courseId = courseId_;
@synthesize courseTitle = courseTitle_;
@synthesize courseDescription = courseDescription_;
@synthesize courseResources = courseResources_;
@synthesize courseEvents = courseEvents_;

//Designated initializer
- (id)initWithDictionary:(NSDictionary *)dictionary
{
    self = [super init];
    if (self) {
        // Initialization code here.
        self.courseId = [dictionary objectForKey:@"course_id"];
        self.courseTitle = [dictionary objectForKey:@"course_title"];
        self.courseDescription = [dictionary objectForKey:@"course_description"];
        self.courseResources = [NSMutableArray array];
        for (NSDictionary *resourceDictionary in [dictionary objectForKey:@"course_resources"]) {
            [self.courseResources addObject:[Resource resourceWithDictionary:resourceDictionary]];
        }
        self.courseEvents = [NSMutableArray array];
        for (NSDictionary *eventDictionary in [dictionary objectForKey:@"course_events"]) {
            [self.courseEvents addObject:[Event eventWithDictionary:eventDictionary]];
        }
    }
    
    return self;
}

- (id)init
{
    return [self initWithDictionary:nil];
}

+ (Course *)courseWithDictionary:(NSDictionary *)dictionary {
    return [[[Course alloc] initWithDictionary:dictionary] autorelease];
}

- (UIImage *)courseImage {
    return [UIImage imageNamed:@"course.png"];
}

- (void)dealloc {
    [courseId_ release];
    [courseTitle_ release];
    [courseDescription_ release];
    [courseResources_ release];
    [courseEvents_ release];
    [super dealloc];
}

@end
